public class ThreadDemo1{

    public static void main(String[] args)  {
        Object locker=new Object();

        Thread t1 =new Thread(()->{
            synchronized (locker){
                System.out.println("before t1 wait");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("after t1 wait");
            }
        });

        Thread t2 =new Thread(()->{
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (locker){
                System.out.println("before t2 notify");
                locker.notify();
                System.out.println("after t2 notify");
        }
    });

        t1.start();
        t2.start();

    }
}
